package com.hp.util;
import java.text.SimpleDateFormat;
import java.util.TimeZone;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;


public class ObjectMapper extends com.fasterxml.jackson.databind.ObjectMapper {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ObjectMapper() {
		// 设置为北京时间
		setTimeZone(TimeZone.getTimeZone("GMT+8"));
		// 序列化时，日期的统一格式
		setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
		// 去掉默认的时间戳格式
		// configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

		// 空值不序列化
		setSerializationInclusion(Include.NON_NULL);
		// 反序列化时，属性不存在的兼容处理
		getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

		// map null 值不处理
		configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
		// 空bean异常忽略
		configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
		// 位置属性异常忽略
		configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		// 单引号处理
		configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);

	}
}